import Mock from '../mock-class.js'

const menus = [
	{
		id: 1,
		name: 'home',
		children: [],
		meta: {
			title: '工作台',
		}
	},
	{
		id: 2,
		name: 'system',
		children: [
			{
				id: 5,
				name: 'user',
				children: [],
				meta: {
					title: '用户管理',
				}
			},
			{
				id: 4,
				name: 'role',
				children: [],
				meta: {
					title: '角色管理',
				}
			},
			{
				id: 20,
				name: 'department',
				children: [],
				meta: {
					title: '部门管理',
				}
			},
			{
				id: 3,
				name: 'menu',
				children: [],
				meta: {
					title: '菜单管理',
				}
			},
			{
				id: 6,
				name: 'permission',
				children: [],
				meta: {
					title: '权限管理',
				}
			},
		],
		meta: {
			title: '系统管理',
		}
	},
	{
		id: 7,
		name: 'comp',
		children: [
			{
				id: 13,
				name: 'divider',
				children: [],
				meta: {
					title: 'Divider分割线',
				}
			},
			{
				id: 8,
				name: 'feedback',
				children: [
					{
						id: 10,
						name: 'drawer',
						children: [],
						meta: {
							title: 'Drawer抽屉',
						}
					}
				],
				meta: {
					title: '反馈组件',
				}
			},
			{
				id: 9,
				name: 'form',
				children: [
					{
						id: 11,
						name: 'input',
						children: [],
						meta: {
							title: 'Input输入框',
						}
					},
					{
						id: 12,
						name: 'rate',
						children: [],
						meta: {
							title: 'Rate评分',
						}
					}
				],
				meta: {
					title: '表单组件',
				}
			},
		],
		meta: {
			title: '组件管理',
		}
	}
]
const perissions = [
	{
		id: 2,
		name: 'add',
		desc: '添加',
		createTime: '2022-04-10 12:25:36'
	},
	{
		id: 3,
		name: 'edit',
		desc: '编辑',
		createTime: '2022-04-10 12:25:36'
	},
	{
		id: 4,
		name: 'delete',
		desc: '删除',
		createTime: '2022-04-10 12:25:36'
	},
	{
		id: 5,
		name: 'detail',
		desc: '详情',
		createTime: '2022-04-10 12:25:36'
	},
]

var code = 200
var data = null
var message = ''

Mock.mock(Mock.baseURL + '/login', 'post', function (options) {
	const { username, password } = JSON.parse(options.body)
	if (username !== 'admin') {
		code = 3001
		data = null
		message = '账号不存在'
	} else if (username == 'admin' && password !== '123456') {
		code = 3002
		data = null
		message = '密码错误'
	} else {
		code = 200
		data = {
			menus: menus,
			permissions: perissions,
			userInfo: {
				id: 1,
				username: username,
				role: {
					id: 1,
					name: '超级管理员'
				},
				nickname: '周帅',
				phone: '13755609011',
				email: '2436509528@qq.com'
			}
		}
		message = '登陆成功'
	}
	
	return {
		code,
		data,
		message
	}
})